//
//  BGMessageListCellView.m
//  bigMall
//
//  Created by LTOVE on 16/7/26.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGMessageListCellView.h"
#import "LTOVELabelEdgInsert.h"
@implementation BGMessageListCellView

+ (UIView *)initWithFrame:(CGRect)frame andIsColor:(BOOL)isColor andIsBid:(BOOL)isBid andUserName:(NSString *)userName andDateText:(NSString *)dateText andContentText:(NSString *)context
{
    BGMessageListCellView *view = [[BGMessageListCellView alloc]initWithFrame:frame];
    view.backgroundColor = lightwhite_;
    [view addSubviewsWithView:view andIsColor:isColor andIsBid:isBid andUserName:userName andDateText:dateText andContentText:context];
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(BGMaginLeft, view.height - 1, screenW - 2 * BGMaginLeft, 1)];
    lineView.backgroundColor = dockwhite_;
    [view addSubview:lineView];
    return view;
}

- (void)addSubviewsWithView:(UIView *)view andIsColor:(BOOL)isColor andIsBid:(BOOL)isBid andUserName:(NSString *)userName andDateText:(NSString *)dateText andContentText:(NSString *)context
{
    
        UILabel *userNameLabel = [[UILabel alloc]init];
        userNameLabel.text = userName;
        userNameLabel.font = BGContenttextSize;
        userNameLabel.textColor = [UIColor blackColor];
        [userNameLabel sizeToFit];
        userNameLabel.point = CGPointMake(30, 20);
        [view addSubview:userNameLabel];
        
        UILabel *dateLabel = [[UILabel alloc]init];
        dateLabel.text = dateText;
        dateLabel.font = BGContenttextSize;
        dateLabel.textColor = BGtextGraykColor;
        [dateLabel sizeToFit];
        dateLabel.x = view.width - dateLabel.width - 30;
        dateLabel.centerY = userNameLabel.centerY;
        [view addSubview:dateLabel];
        
        NSDictionary *attDict = @{
                                  NSFontAttributeName:BGContenttextSize,
                                  NSForegroundColorAttributeName:[UIColor blackColor]
                                  };
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:context attributes:attDict];
        if (isColor) {
            [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, context.length - 2)];
        }else{
            [attStr addAttribute:NSForegroundColorAttributeName value:BGtextGraykColor range:NSMakeRange(0, context.length)];
        }
        UILabel *contentLabel = [[UILabel alloc]init];
        contentLabel.attributedText = attStr;
        contentLabel.point = CGPointMake(userNameLabel.x, CGRectGetMaxY(userNameLabel.frame) + 5);
        [contentLabel sizeToFit];
        [view addSubview:contentLabel];
        
        LTOVELabelEdgInsert *bidLabel = [[LTOVELabelEdgInsert alloc]init];
        bidLabel.contentMode = UIViewContentModeCenter;
        bidLabel.backgroundColor = isBid ? [UIColor redColor] : BGtextGraykColor;
        bidLabel.textColor = [UIColor whiteColor];
        bidLabel.font = Font30;
        bidLabel.text = isBid ? @"已中标" : @"未中标";
        [bidLabel sizeToFit];
        bidLabel.contentInsets = UIEdgeInsetsMake(1, 5, 1, 5);
        
        //    bidLabel.width = bidLabel.width + 10;bgm
        //    BGMaginTop
        bidLabel.clipsToBounds = YES;
        bidLabel.layer.cornerRadius = 5;
        
        
        bidLabel.centerX = dateLabel.centerX;
        bidLabel.y = CGRectGetMaxY(dateLabel.frame) + 5;
        
        bidLabel.hidden = isColor;
        
        [view addSubview:bidLabel];

   
    
}
@end
